home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CMIDI 2.2 / CMIDIInputPort.cp < prev    next >
Encoding:
Text File  |  1994-11-30  |  4.2 KB  |  122 lines  |  [TEXT/KAHL]

  1. /*
  2.  *——— CMIDIInputPort.cp ————————————————————————————————————————————————————————————————
  3.  * Copyright © Paul Ferguson, 1990-94.  All rights reserved.
  4.  *
  5.  *    Superclass:     CDataPort
  6.  *    Subclasses:     None
  7.  *
  8.  * Description:
  9.  *    CMIDIInputPort.c defines a MIDI Manager port object.
  10.  *
  11.  *    For use with Symantec C++ 6.0, the accompanying THINK Class Library (TCL), and MIDI
  12.  *    Manager 2.0. Refer to the accompanying Microsoft Word document for complete
  13.  *    details about MIDI Manager objects.
  14.  *
  15.  *    If you have comments or questions about this code, you can reach me on
  16.  *    CompuServe at 70441,3055.
  17.  *
  18.  *——————————————————————————————————————————————————————————————————————————————————————
  19.  *———— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ——— NOTE ————
  20.  *——————————————————————————————————————————————————————————————————————————————————————
  21.  *    If you are not familiar with programming the Apple MIDI Manager, refer to the
  22.  *    "MIDI Management Tools" Version 2.0, available from APDA.  You MUST have the
  23.  *    software (MIDI.H and the library) from this package in order to use these objects.
  24.  *    It will not work without this.
  25.  *——————————————————————————————————————————————————————————————————————————————————————
  26.  *    REVISION HISTORY:
  27.  *        August ??, 1990            - Original release (1.0).
  28.  *        November 5, 1990        - Added checks for midiMgrVer to most methods.
  29.  *        August 1991                - updated for THINK C 5.0 as version 2.0
  30.  *        July 1993                - updated for Symantec C 6.0. Made simple methods inline
  31.  *——————————————————————————————————————————————————————————————————————————————————————
  32.  */
  33.  
  34. #include "CMIDIInputPort.h"
  35. #include "CMIDITimePort.h"
  36.  
  37. static const int midiPoll = 104;            // From MIDI.a
  38. static const int midiDiscardPacket = 176;
  39.  
  40. static    pascal void (*CMIDIInputPort::midiDiscardProc) (short theRefNum, MIDIPacketPtr thePacket);
  41. static    pascal void (*CMIDIInputPort::midiPollProc) (short theRefNum, long theOffsetTime);
  42. static    pascal void (*CMIDIInputPort::midiFlushProc) (short theRefNum);
  43.  
  44. /*
  45.  *——— CMIDIInputPort::IMIDIInputPort ——————————————————————————————————————————
  46.  * Initialize Input Port. This method sets up the MIDIPortParams data structure
  47.  * and calls CMIDIPort::IMIDIPort().  If version is >= 2.0, then save any
  48.  * direct ProcPtrs.
  49.  *—————————————————————————————————————————————————————————————————————————————
  50.  */
  51.  
  52. OSErr CMIDIInputPort::IMIDIInputPort(StringPtr            theName,
  53.                                      OSType                thePortID,
  54.                                        Boolean            theVisibleFlag,
  55.                                      CMIDITimePort *    theTimePort,
  56.                                      long               theOffset,
  57.                                      short              theBufSize,
  58.                                      ProcPtr              theReadHook)
  59. {
  60.     MIDIPortParams    portParams;        // MIDI Mgr Init data structure
  61.     OSErr            theResult;
  62.     
  63.     portParams.portID            = thePortID;
  64.     portParams.portType            = midiPortTypeInput;
  65.     if ( (theVisibleFlag == FALSE) && (itsVersion >= 0x0200) )    // Invisible input port, in 2.x
  66.         portParams.portType        |= midiPortInvisible;
  67.  
  68.     portParams.timeBase            = theTimePort ? theTimePort->GetRefNum() : 0;
  69.     portParams.offsetTime        = theOffset;
  70.     portParams.readHook            = (Ptr) theReadHook;
  71.     portParams.refCon            = SetCurrentA5();
  72.     BlockMove(theName, portParams.name, theName[0]+1);
  73.  
  74.     theResult = IMIDIPort(&portParams, theBufSize);
  75.     if (itsVersion >= 0x0200)
  76.     {
  77.         midiDiscardProc    = (pascal void (*) (short, MIDIPacketPtr)) MIDICallAddress(midiDiscardPacket);
  78.         midiPollProc    = (pascal void (*) (short, long)) MIDICallAddress(midiPoll);
  79.     }
  80.     return theResult;
  81. }
  82.  
  83. #ifndef __cplusplus
  84.  
  85.     // if using THINK C compiler, not Symantec C++, these are non-inline methods.
  86.     
  87.     ProcPtr    CMIDIInputPort::GetReadHook(void)
  88.     {
  89.         return (itsVersion ? MIDIGetReadHook(itsRefNum) : 0);
  90.     }
  91.     
  92.     void    CMIDIInputPort::SetReadHook(ProcPtr theReadHook)
  93.     {
  94.         if (itsVersion)
  95.             MIDISetReadHook(itsRefNum, theReadHook);
  96.     }
  97.     
  98.     void    CMIDIInputPort::Flush(void)
  99.     {
  100.         if (itsVersion >= 0x0200)
  101.             (*midiFlushProc) (itsRefNum);
  102.         else
  103.             if (itsVersion) MIDIFlush(itsRefNum);
  104.     }
  105.     
  106.     void    CMIDIInputPort::Poll(long offsetTime)
  107.     {
  108.         if (itsVersion >= 0x0200)
  109.             (*midiPollProc) (itsRefNum, offsetTime);
  110.         else
  111.             if (itsVersion) MIDIPoll(itsRefNum, offsetTime);
  112.     }
  113.     
  114.     void    CMIDIInputPort::DiscardPacket(MIDIPacketPtr thePacket)
  115.     {
  116.         if (itsVersion >= 0x0200)        // Only valid on MM 2.0 or later!
  117.             (*midiDiscardProc) (itsRefNum, thePacket);
  118.     }
  119. #endif
  120.  
  121. // end of CMIDIInputPort.cp
  122.